<template>
  <el-dialog
    title="预览文章"
    :visible="showPreview"
    @close="$emit('update:showPreview', false)"
    @open="open"
  >
    <h2>
      {{ article.title }}
    </h2>
    <el-row class="description">
      <span>{{ article.createTime | parseTimeByString }}</span>
      <span>超级管理员</span>
      <span
        ><i class="el-icon-view" style="margin-right: 5px"></i
        >{{ article.visits }}</span
      >
    </el-row>
    <div class="content" v-html="article.articleBody"></div>
  </el-dialog>
</template>

<script>
import { detail } from '@/api/hmmm/articles'
export default {
  name: 'ArticlePreview',
  props: {
    showPreview: {
      type: Boolean,
      default: true
    },
    id: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      article: {}
    }
  },
  methods: {
    async open () {
      const { data } = await detail(this.id)
      this.article = data
      console.log(data)
    }
  }
}
</script>

<style lang="scss" scoped>
h2 {
  margin: 0;
}
.description {
  padding: 10px;
  span {
    padding: 5px;
  }
}
.content {
  padding: 10px;
  background-color: #f5f5f5;
  border-top: 1px dashed #ccc;
}
</style>
